$(function () {
    //初始化
    var shopListUrl = '/o2o/shopadmin/getshoplist';

    getlist();

    function getlist(e) {
        $.ajax({
            url: shopListUrl,
            type: "get",
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    handleList(data.shopList);
                    handleUser(data.user);
                }
            }
        });
    }

    /**
     * 将页面的userName赋值
     * @param data
     */
    function handleUser(user) {
        $("#user-name").text(user.name)
    }

    /**
     * 渲染店铺列表的页面
     * @param data
     */
    function handleList(shopList) {
        var html = '';
        shopList.map(function (item, index) {
            html += '<div class="row row-shop"><div class="col-40">'
                + item.shopName + '</div><div class="col-40">'
                + shopStatus(item.enableStatus) + '</div><div class="col-20">'
                + goShop(item.enableStatus, item.shopId)
                + '</div></div>';
        });
        $('.shop-wrap').html(html);
    }

    function goShop(status, shopId) {
        if (status != 0 && status != -1) {
            return '<a href="/o2o/shopadmin/shopmanagement?shopId='+ shopId +'">进入</a>';
        } else {
            return '';
        }
    }

    function shopStatus(status) {
        if (status == 0) {
            return '审核中';
        } else if (status == -1) {
            return '店铺非法';
        } else {
            return '审核通过';
        }
    }



})
